import request from '../libs/request';
export function post(url, params = {}) {
    return new Promise((resolve, reject) => {
        request
          .post(url, params,{
              headers: {
                  'Content-Type': 'application/json;charset=UTF-8'  //请求头
              }
          })
          .then(response => {
              resolve(response.data)
          })
          .catch(error => {
              reject(error)
          })
    })
}
export function postParams(url, params = {}) {
    return new Promise((resolve, reject) => {
        request.request({
            url:  url,
            method: "post",
            params: params,
            headers: {
                'Content-Type': 'application/json;charset=UTF-8'  //请求头
            }
        })
            .then(response => {
                resolve(response.data);
            })
            .catch(error => {
                reject(error);
            })
    })
}
export function get(url, params ={}) {
    return new Promise((resolve, reject) => {
        request
          .get(url,{
              params: params
          },{
              headers: {
                  'Content-Type': 'application/json;charset=UTF-8'  //请求头
              }
          })
          .then(response => {
              resolve(response.data)
          })
          .catch(error => {
              reject(error)
          })
    })
}

export function uploadPost (url, formData) {
    if (formData instanceof FormData) {
        return new Promise((resolve, reject) => {
            request.request({
                  url:  url,
                  method: "post",
                  data: formData,
                  headers: {
                      'Content-Type': 'multipart/form-data'  //请求头
                  }
              })
              .then(response => {
                  resolve(response.data);
              })
              .catch(error => {
                  reject(error);
              })
        })
    } else {
        console.error('格式错误，需要传入FormData格式');
    }
}

export function otherPostParams(url, params = {},configUrl) {
  return new Promise((resolve, reject) => {
    request.request({
        url:  url,
        method: "post",
        params: params,
        isCommon:configUrl,
        headers: {
          'Content-Type': 'application/json;charset=UTF-8'  //请求头
        }
      })
      .then(response => {
        resolve(response.data);
      })
      .catch(error => {
        reject(error);
      })
  })
}

export function otherGetParams(url, params = {},configUrl) {
  return new Promise((resolve, reject) => {
    request.request({
        url:  url,
        method: "get",
        params: params,
        isCommon:configUrl,
        headers: {
          'Content-Type': 'application/json;charset=UTF-8'  //请求头
        }
      })
      .then(response => {
        resolve(response.data);
      })
      .catch(error => {
        reject(error);
      })
  })
}
